from pyspark.sql import SparkSession
spark=SparkSession.builder.master('local').appName('w2v').getOrCreate()

from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.feature import StringIndexer,IndexToString

df=spark.createDataFrame([(0,'a'),(1,'b'),(2,'c'),(3,'a'),(4,'a'),(5,'c')],["id","category"])
indexer=StringIndexer(inputCol="category",outputCol="categoryIndex")#转换器

model=indexer.fit(df)#训练
indexed=model.transform(df)
# indexed.show()


toString=IndexToString(inputCol="categoryIndex",outputCol="originalCategory")
indexString=toString.transform(indexed)
indexString.select("id","originalCategory").show()

